import axios from "axios";
import { message } from "antd";
import { baseUrlPath } from "@config";

axios.interceptors.response.use(
  (response) => {
    if (response.status !== 200) {
      message.error(`网络请求报错：${response.statusText}`);
    }
    if (
      response.data.error_code !== undefined &&
      response.data.error_code !== 0 &&
      response.data.error_code !== 4117 &&
      response.headers["content-type"] !== "application/octet-stream"
    ) {
      message.error(`接口请求报错，错误信息：${response.data.message}`);
    }
    // if (response.data.error_code === 4001) {
    //   const { url } = envData;
    //   location.href = `${url}${baseUrlPath.login}&redirect_url=${encodeURIComponent(`${location.href}`)}`;
    // }
    return response;
  },
  (error) => Promise.reject(error)
);

export default axios;
